<%@page import="dao.Course"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<%
	Course course = (Course)session.getAttribute("course");
	int chapterCounts = course.getChaptercounts();
	
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>添加知识点</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
body {
	font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica,
		sans-serif;
	color: #4f6b72;
	text-align: center;
	background: #E6EAE9;
}

#container {
	margin-left: auto;
	margin-right: auto;
	width: 1000px;
	height: 700px;
	background: #f8f8f8;
	border: 2px solid #777;
	display: block;
	vertical-align: middle;
}

.ele {
	margin-top: 30px;
	margin-botton: 30px;
	text-align: center;
	width: 100%;
	display: block;
	vertical-align: middle;
}
</style>
<script type="text/javascript">
function checkData(){
	var chapterId = document.getElementById("chapterId").value.trim();
	var knowledgeType = document.getElementById("knowledgeType").value.trim();
	var description = document.getElementById("description").value.trim();
	var title = document.getElementById("title").value.trim();
	if(title !="" && chapterId !="choose" && knowledgeType !="choose" && description!=""){
			return true;					
	}else{
		alert("请填写完整！");
		return false;
	}
	function addChapters(){
		var obj = document.getElementById("chapterId");
		var counts = <%=chapterCounts %>;
		var courseid = <%=course.getCourseid() %>;
		for(var i=1;i<=counts;i++){
			var str;
			var value
			if(i<10){
				value = courseid + "0" +i;
			}else{
				value = courseid + i;
			}
			obj.options[i+1] = new Option("第"+i+"章",value);
		}
	}
	
}

</script>
</head>
<body>
	<h2>添加知识点</h2>
	<div id="container">
		<form name="knowledgeForm" method="post" enctype="multipart/form-data"
			action="./servlet/KnowledgeManageServlet?action=add"
			onsubmit="return checkData()">
			<div class="ele">
				<label> 所属章节： </label>
				<select name="chapterId" id="chapterId">
						<option value="choose" selected="selected">请选择章节</option>
				</select>
			</div>
			<div class="ele">
				<label> 标题：</label>
				 <input type="text" name="title" id="title" > 
			</div>
			<div class="ele">
				<label> 知识点类型： </label> <select name="knowledgeType"
					id="knowledgeType">
					<option value="choose">请选择知识点类型</option>
					<option value="normal">普通知识点</option>
					<option value="important">重点</option>
					<option value="difficult">难点</option>
				</select>
			</div>
			<div class="ele">
				<label> 知识点介绍： </label>
				<textarea rows="7" cols="65" id="description" name="description"></textarea>
			</div>
			<div class="ele">
				<label> 实例（文字）： </label>
				<textarea name="example" id="example" rows="7" cols="65"></textarea>
			</div>
			<div class="ele">
				<label> 实例（图片）： </label> <input type="file" name="path" id="path">
			</div>
			<div class="ele">
				<input type="submit" value="提交"> <input type="reset"
					value="取消">
			</div>
		</form>
	</div>
	<script type="text/javascript">
	var obj = document.getElementById("chapterId");
	var counts = <%=chapterCounts %>;
	var courseid = "<%=course.getCourseid() %>";
	for(var i=1;i<=counts;i++){
		var str;
		var value
		if(i<10){
			value = courseid + "0" +i;
		}else{
			value = courseid + i;
		}
		obj.options[i] = new Option("第"+i+"章",value);
	}
	</script>
	<%
	    if (request.getAttribute("success") != null) {
				String str = (String) request.getAttribute("success");
				if ("true".equals(str)) {
				    out.write("<script>alert('添加成功！')</script>");
				} else if ("false".equals(str)) {
				    out.write("<script>alert('添加失败！')</script>");
				}
	    }
	%>
</body>
</html>
